package com.gitee.huanminabc.demo.controller;

import com.gitee.huanminabc.demo.model.converter.WorkEntityToVoConverter;
import com.gitee.huanminabc.demo.model.converter.WorkLogEntityToVoConverter;
import com.gitee.huanminabc.demo.model.entity.WorkEntity;
import com.gitee.huanminabc.demo.model.entity.WorkLogEntity;
import com.gitee.huanminabc.demo.model.vo.WorkLogVo;
import com.gitee.huanminabc.demo.model.vo.WorkVo;
import com.gitee.huanminabc.demo.service.WorkService;
import com.gitee.huanminabc.nullchain.common.NullResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@Api(tags = "WorkController")
@RestController
@RequestMapping("/work")
public class WorkController {

    @Autowired
    private WorkService workService;
    @Autowired
    private WorkEntityToVoConverter workEntityToVoConverter;
    @Autowired
    private WorkLogEntityToVoConverter workLogEntityToVoConverter;
    //保存工单
    @PostMapping(value = "/save")
    @ApiOperation(value = "保存工单")
    public NullResult<Boolean> save(@Validated @RequestBody WorkVo workVo) {
        workService.save(workVo);
        return NullResult.success(true);
    }
    //查询工单日志
    @PostMapping(value = "/getWorkLog")
    @ApiOperation(value = "查询工单")
    public NullResult<WorkLogVo> getWorkLog(@RequestParam("workId") String workId) {
        WorkLogEntity workLogEntity = workService.getWorkLog(workId);
        return NullResult.success(workLogEntityToVoConverter.toVO(workLogEntity));
    }
    //查询工单
    @PostMapping(value = "/getWork")
    @ApiOperation(value = "查询工单")
    public NullResult<WorkVo> getWork(@RequestParam("workId") String workId) {
        WorkEntity work = workService.getWork(workId);
        return NullResult.success(workEntityToVoConverter.toVO(work));
    }

}
